﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AuroraWuBi
{
    //多条件排序

      public  class Words
    {
        public string word { get; set; }//字词
        public string code { get; set; } //五笔编码
        public int frequency1 { get; set; }// 第一字词频
        public int frequency1500 { get; set; }//常用1500字
        public int frequencyCYHZ { get; set; }//常用8105字
        public int frequency2 { get; set; }// 第二字词频
        public int frequency3 { get; set; }// 在各个主流码表累计出现的次数
        public int wordsNum { get; set; }//字词长度

        public  Words(string word, string code,int wordsNum, int frequency1, int frequency1500,  int frequency2, int frequency3, List<string> cyhz)
        {

            this.word = word;
            this.code = code;
            this.frequency1 = frequency1;
            this.frequency1500 = frequency1500;
            this.frequency2 = frequency2;
            this.frequency3 = frequency3;
            this.wordsNum = wordsNum;
            if (cyhz.Contains(word))
                this.frequencyCYHZ = 1;
            else
                this.frequencyCYHZ = 0;
        }
    }
   public  class SortWords
    {
        //单字词语混合排序
        public static  int SortByID(Words w1, Words w2)
        {
            if (w1.frequency1.CompareTo(w2.frequency1) != 0)
                return -(w1.frequency1.CompareTo(w2.frequency1));//按第一字词频降序
            else if (w1.frequency1500.CompareTo(w2.frequency1500) != 0)
                return -(w1.frequency1500.CompareTo(w2.frequency1500));//常用1500字降序
            else if (w1.frequencyCYHZ.CompareTo(w2.frequencyCYHZ) != 0)
                return -(w1.frequencyCYHZ.CompareTo(w2.frequencyCYHZ));//按常用8105降序
            else if (w1.frequency2.CompareTo(w2.frequency2) != 0)
                return -(w1.frequency2.CompareTo(w2.frequency2));//按第二字词频降序
            else if (w1.frequency3.CompareTo(w2.frequency3) != 0)
                return -(w1.frequency3.CompareTo(w2.frequency3));//在各个主流码表累计出现的次数降序
            else if (w1.wordsNum.CompareTo(w2.wordsNum) != 0)
                return -(w1.wordsNum.CompareTo(w2.wordsNum));//按字词长度降序
            else if(w1.word.CompareTo(w2.word) != 0)
                return (w1.word.CompareTo(w2.word));//按字升序
            else
                return 1;
        }

        //单字生成简码排序
        public static int SortByID2(Words w1, Words w2)
        {
            if (w1.frequency1.CompareTo(w2.frequency1) != 0)
                return -(w1.frequency1.CompareTo(w2.frequency1));//按第一字词频降序
            else if (w1.frequency1500.CompareTo(w2.frequency1500) != 0)
                return -(w1.frequency1500.CompareTo(w2.frequency1500));//常用1500字降序
            else if (w1.frequencyCYHZ.CompareTo(w2.frequencyCYHZ) != 0)
                return -(w1.frequencyCYHZ.CompareTo(w2.frequencyCYHZ));//按常用8105降序
            else if (w1.frequency2.CompareTo(w2.frequency2) != 0)
                return -(w1.frequency2.CompareTo(w2.frequency2));//按第二字词频降序
            else if (w1.frequency3.CompareTo(w2.frequency3) != 0)
                return -(w1.frequency3.CompareTo(w2.frequency3));//在各个主流码表累计出现的次数降序
            else if (w1.wordsNum.CompareTo(w2.wordsNum) != 0)
                return -(w1.wordsNum.CompareTo(w2.wordsNum));//按字词长度降序
            else if (w1.word.CompareTo(w2.word) != 0)
                return (w1.word.CompareTo(w2.word));//按字升序
            else
                return 1;
        }


        public static void testSortWords()
        {
            List<Words> mywords = new List<Words>()
            {
                new Words("工12","aa",1,557,0,0,1,new List<string> { "a","b"}),
                new Words("工13","aa",1,557,0,0,1,new List<string> { "a","b"})

            };
            foreach (Words w in mywords)
            {
                Console.WriteLine(string.Format("{0}\t{1}\t{2}\t{3}\t{4}", w.frequency1500, w.word, w.code, w.frequency1, w.frequency2));

            }
            Console.WriteLine("================================================");

            mywords.Sort(SortWords.SortByID);
            foreach (Words w in mywords)
            {
                Console.WriteLine(string.Format("{0}\t{1}\t{2}\t{3}\t{4}", w.frequency1500, w.word, w.code, w.frequency1, w.frequency2));

            }
            Console.WriteLine("================================================");

           

            Console.ReadLine();
        }
    }
}
